package com.tanjun.thirdservice.web.controller;

import com.tanjun.common.constants.UrlConstant;
import com.tanjun.common.model.R;
import com.tanjun.thirdservice.request.WxCode2PhoneVo;
import com.tanjun.thirdservice.request.WxCode2UserVo;
import com.tanjun.thirdservice.response.WxCode2PhoneDto;
import com.tanjun.thirdservice.response.WxCode2UserDto;
import com.tanjun.thirdservice.web.biz.WxUserBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import jakarta.validation.Valid;
import java.time.LocalDateTime;

/**
 * 微信用户服务接口
 */
@RestController
public class WxUserController {
    private final String PREX = "/wxUser";
    @Autowired
    private WxUserBiz wxUserBiz;

    @PostMapping(UrlConstant.URL_AUTH.OPEN + PREX + "/jscode2session")
    public R<WxCode2UserDto> jscode2session(@Valid @RequestBody WxCode2UserVo paramVo) {
        return R.OK(wxUserBiz.jscode2session(paramVo));
    }

    /**
     * 获取手机号
     *
     * @param paramVo
     * @return
     */
    @PostMapping(UrlConstant.URL_AUTH.OPEN + PREX + "/getPhoneNumber")
    public R<WxCode2PhoneDto> getPhoneNumber(@Valid @RequestBody WxCode2PhoneVo paramVo) {
        return R.OK(wxUserBiz.getPhoneNumber(paramVo));
    }


    @GetMapping(UrlConstant.URL_AUTH.OPEN + PREX + "/now")
    public R<LocalDateTime> now() {
        return R.OK(LocalDateTime.now());
    }
}
